//
//  STTools_HomeTableViewCell.m
//  FindFriend
//
//  Created by apple on 2020/9/3.
//  Copyright © 2020 stoneobs. All rights reserved.
//

#import "THTreeHoleVideoCollectionViewCell.h"

@interface THTreeHoleVideoCollectionViewCell()
@property(nonatomic, strong) UIImageView                     *iconImagView;/**<  */
@property(nonatomic, strong) STLabel                     *nameLable;/**<  */
@property(nonatomic, strong) STLabel                     *userLable;/**<  */
@property(nonatomic, strong) STButton                     *userButton;/**<  */
@property(nonatomic, strong) UIView                     *whiteView;/**<  */
@property(nonatomic, strong) CALayer                     *sublayer;/**<  */
@end
@implementation THTreeHoleVideoCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self stoneobs_ui_configSubView];
    }
    return self;
}

#pragma mark --configSubView
- (void)stoneobs_ui_configSubView{
    self.whiteView = UIView.new;
    self.whiteView.backgroundColor = UIColor.whiteColor;
    self.whiteView.layer.cornerRadius = 4;
    self.whiteView.clipsToBounds = YES;
    [self addSubview:self.whiteView];
    
    UIImageView * icon_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, UISCREEN_WIDTH - 30, 345)];
    icon_imageView.image = [UIImage imageNamed:@"ic_none"];
    icon_imageView.contentMode = UIViewContentModeScaleAspectFill;
    icon_imageView.clipsToBounds = YES;
    [self addSubview:icon_imageView];
    self.iconImagView = icon_imageView;

    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(5, 0, self.iconImagView.width - 10, 35)
                                                                text:@"#可爱萝莉、魅力大方、甜..."
                                                           textColor:STONEOBS_UI_FIRST_TEXT_COLOR
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        self.nameLable = stoneobs_ui_label;
        [self addSubview:stoneobs_ui_label];
    });
    
    ({
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(5, 0, 20, 20)
                                                                  title:nil
                                                             titleColor:nil
                                                              titleFont:0
                                                           cornerRadius:10
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:nil];
        
        [self addSubview:stoneobs_ui_button];
        self.userButton = stoneobs_ui_button;
        __weak typeof(self) weakSelf =  self;
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [TMUtils goto_user_info_witdh_id:weakSelf.model.user_id];
        }];
    });
    
    ({
        STLabel * stoneobs_ui_label = [[STLabel alloc] initWithFrame:CGRectMake(self.userButton.right+5, 0, 100, 20)
                                                                text:@"sas"
                                                           textColor:WH_UICOLOR_FROM_RGBA(0x343434)
                                                                font:12
                                                         isSizetoFit:NO
                                                       textAlignment:NSTextAlignmentLeft];
        self.userLable = stoneobs_ui_label;
        [self addSubview:stoneobs_ui_label];
        
    });
    
    ({
        __weak typeof(self) weakSelf =  self;
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(5, 0, 55, 20)
                                                                  title:@"213"
                                                             titleColor:WH_UICOLOR_FROM_RGBA(0x9A9A9A)
                                                              titleFont:10
                                                           cornerRadius:0
                                                        backgroundColor:nil
                                                        backgroundImage:nil
                                                                  image:ST_IMAGE_NAMED(@"treehole_点赞")];
        [stoneobs_ui_button setImage:ST_IMAGE_NAMED(@"treehole_赞") forState:UIControlStateSelected];
        stoneobs_ui_button.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 5);
        [stoneobs_ui_button setTitleColor:FlatRed forState:UIControlStateSelected];
        [self addSubview:stoneobs_ui_button];
        self.goodButton = stoneobs_ui_button;
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            [THTreeHoleDataController addGoodOrCancleFormPosts_id:weakSelf.model.t_id handle:^(NSError *error, BOOL success, NSDictionary *resp) {
               
                sender.selected = !sender.selected;
                weakSelf.model.is_up =  !weakSelf.model.is_up;
                if (weakSelf.model.is_up) {
                    weakSelf.model.up_num = weakSelf.model.up_num+1;
                }else{
                    weakSelf.model.up_num = weakSelf.model.up_num-1;
                }
                [sender setTitle:@(weakSelf.model.up_num).description forState:UIControlStateNormal];
            }];
        }];
    });
    
    
        STButton * stoneobs_ui_button = [[STButton alloc] initWithFrame:CGRectMake(0, 10, 40, 40)
                                                                  title:nil
                                                             titleColor:UIColor.whiteColor
                                                              titleFont:12
                                                           cornerRadius:20
                                                        backgroundColor:WH_UICOLOR_FROM_RGBA(0xEEEEEE)
                                                        backgroundImage:nil
                                                                  image:ST_IMAGE_NAMED(@"删除_white")];
        self.deleteButton = stoneobs_ui_button;
        stoneobs_ui_button.right = self.width - 15;
        [stoneobs_ui_button setClicAction:^(UIButton *sender) {
            
        }];
        stoneobs_ui_button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
        [self addSubview:stoneobs_ui_button];
    self.deleteButton.hidden = YES;
}
- (void)setModel:(THTieZiModel *)model{
    _model = model;
    
    if (self.model.cus_is_mine){
        self.deleteButton.hidden = NO;
    }
    if (model.imgs.count) {
        [self.iconImagView sd_setImageWithURL:model.imgs.firstObject.mj_url];
    }else{
        [self.iconImagView sd_setImageWithURL:model.user_header_img.mj_url];
    }
    


    self.nameLable.text = model.title;
    [self.userButton sd_setBackgroundImageWithURL:model.user_header_img.mj_url forState:UIControlStateNormal];
    
    self.userLable.text = [NSString stringWithFormat:@"%@",model.user_name];

    
    self.goodButton.selected = model.is_up;
    [self.goodButton setTitle:@(model.up_num).description forState:UIControlStateNormal];
    
}
- (void)layoutSubviews{
    
    self.whiteView.frame = self.bounds;
    [self.sublayer removeFromSuperlayer];
    self.sublayer =  [self.whiteView stoneobs_fun_st_showRoundLayer];
    self.deleteButton.right = self.width - 10;
    

    self.userButton.bottom = self.height - 7;
    self.userLable.centerY = self.userButton.centerY;
    self.goodButton.centerY = self.userButton.centerY;
    self.goodButton.right = self.width - 5;
    
    self.nameLable.width = self.width - 10;
    self.nameLable.bottom = self.userButton.top - 5;
    
    self.iconImagView.frame = CGRectMake(0, 0, self.width, self.nameLable.top - 3);
}
@end
